package com.file.manage.infrastructure.dao.impl;


import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.file.manage.domain.entity.OperationLogs;
import com.file.manage.domain.entity.User;
import com.file.manage.domain.param.OperationLogsQueryParam;
import com.file.manage.infrastructure.base.dao.impl.BaseDaoImpl;
import com.file.manage.infrastructure.dao.OperationLogsDao;
import com.file.manage.infrastructure.mapper.OperationLogsMapper;
import org.springframework.stereotype.Repository;

/**
 * @author H41
 * @Type IOperationLogsDaoImpl.java
 * @date 2025/5/31 12:26
 * @Desc
 */
@Repository
public class OperationLogsDaoImpl extends BaseDaoImpl<OperationLogsMapper, OperationLogs> implements OperationLogsDao {
    @Override
    public Page<OperationLogs> pageQuery(Page<OperationLogs> page, OperationLogsQueryParam param) {
        if (param == null) return this.page(page);
        return this.baseMapper.selectPage(page, new LambdaQueryWrapper<OperationLogs>()
                .like(StrUtil.isNotBlank(param.getDes()), OperationLogs::getDes, param.getDes())
                .in(CollUtil.isNotEmpty(param.getUserIds()), OperationLogs::getOperationUser, param.getUserIds())
                .eq(param.getOperationType() != null, OperationLogs::getType, param.getOperationType())
                .ge(param.getStartDate() != null, OperationLogs::getCreatedTime, param.getStartDate())
                .le(param.getEndDate() != null, OperationLogs::getCreatedTime, param.getEndDate())
                .orderByDesc(OperationLogs::getCreatedTime)
        );
    }
}
